# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: inkyu

from collections import namedtuple

FILL_ROW_FIELDS = [
    'time',
    'time_hr',
    'exchange',
    'side',
    'price',
    'qty',
    'pos_1',
    'pos_2',
    'bs_pos',
    'sb_pos',
    'balance_1',
    'balance_2'
]
_FillRow = namedtuple('FillRow', FILL_ROW_FIELDS)

FILL_ROW_SINGLE_FIELDS = ['time', 'time_hr', 'side', 'price', 'qty', 'fee', 'pos', 'balance']
_FillRowSingle = namedtuple('FillRowSingle', FILL_ROW_SINGLE_FIELDS)

FEATURE_ROW_FIELDS = [
    'time',
    'time_hr',
    'ask0_1',
    'bid0_1',
    'askt_1',
    'bidt_1',
    'midt_1',
    'ask0_2',
    'bid0_2',
    'askt_2',
    'bidt_2',
    'midt_2',
    'mid_basis_ma',
    'askp_1',
    'bidp_1',
    'askp_2',
    'bidp_2'
]
_FeatureRow = namedtuple('FeatureRow', FEATURE_ROW_FIELDS)


class FillRow(_FillRow):
  @staticmethod
  def get_header():
    return 'header_fill_dump,%s' % ','.join(FILL_ROW_FIELDS)

  def to_log_string(self):
    return ('\n"FILL_DUMP",%d,"%s",'
            '%d,%d,%f,%f,'
            '%f,%f,%f,%f,%f,%f' % (self.time,
                                   self.time_hr,
                                   self.exchange,
                                   self.side,
                                   self.price,
                                   self.qty,
                                   self.pos_1,
                                   self.pos_2,
                                   self.bs_pos,
                                   self.sb_pos,
                                   self.balance_1,
                                   self.balance_2))


class FillRowSingle(_FillRowSingle):
  @staticmethod
  def get_header():
    return 'header_fill_dump,%s' % ','.join(FILL_ROW_SINGLE_FIELDS)

  def to_log_string(self):
    return (
        '\n"FILL_DUMP",%d,"%s",'
        '%d,%f,%f,%f,'
        '%f,%f' %
        (self.time, self.time_hr, self.side, self.price, self.qty, self.fee, self.pos,
         self.balance))


class FeatureRow(_FeatureRow):
  @staticmethod
  def get_header():
    return 'header_feature_dump,%s' % ','.join(FEATURE_ROW_FIELDS)

  def to_log_string(self):
    return ('\n"FEATURE_DUMP",%d,"%s",'
            '%f,%f,%f,%f,%f,'
            '%f,%f,%f,%f,%f,'
            '%f,%f,%f,%f,%f' % (self.time,
                                self.time_hr,
                                self.ask0_1,
                                self.bid0_1,
                                self.askt_1,
                                self.bidt_1,
                                self.midt_1,
                                self.ask0_2,
                                self.bid0_2,
                                self.askt_2,
                                self.bidt_2,
                                self.midt_2,
                                self.mid_basis_ma,
                                self.askp_1,
                                self.bidp_1,
                                self.askp_2,
                                self.bidp_2))
